package com.ssy.lingxi.member.merchant.repository;

import com.ssy.lingxi.member.merchant.entity.MemberConfigDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 会员注册资料配置JpaRepository
 * @author 万宁
 * @date 2020-05-29
 * @version 2.0.0
 */
@Repository
public interface MemberConfigRepository extends JpaRepository<MemberConfigDO,Long>, JpaSpecificationExecutor<MemberConfigDO> {

    Boolean existsByFieldNameOrFieldLocalName(String fieldName, String fieldLocalName);

    Boolean existsByTagEnum(Integer tagEnum);

    Boolean existsByTagEnumAndIdNot(Integer tagEnum, Long id);

    @Query("select count(id) from MemberConfigDO t where (t.fieldName=:fieldName or t.fieldLocalName=:fieldLocalName) and id<>:id")
    long countByFieldNameOrFieldLocalNameNotEqId(String fieldName, String fieldLocalName, long id);

    List<MemberConfigDO> findByFieldStatusAndIdIn(Integer status, List<Long> ids);
}
